#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <vector>

using namespace std;

struct ListNode {
    int val;
    ListNode* next;
    ListNode(int x) : val(x), next(NULL) {}
};

struct TreeNode {
    int val;
    TreeNode* left;
    TreeNode* right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

class Solution {
   public:
    vector<int> reversePrint(ListNode* head) {
        if (head == NULL)
            return vector<int>();
        //头插法
        ListNode *h = new ListNode(-1), *fast = head->next, *slow = head;
        h->next = head;
        slow->next = NULL;
        while (fast != NULL) {
            slow = fast;
            fast = fast->next;
            slow->next = h->next;
            h->next = slow;
        }
        h = h->next;
        vector<int> ret;
        while (h != NULL) {
            ret.push_back(h->val);
            h = h->next;
        }
        return ret;
    }
};

int main() {
    cout << "Hello, World!";
    ListNode* tmp = new ListNode(0);
    tmp->next = new ListNode(1);
    tmp->next->next = new ListNode(2);
    tmp->next->next->next = new ListNode(3);
    tmp->next->next->next->next = new ListNode(4);
    Solution().reversePrint(tmp);
    return 0;
}